using UnityEngine;
using System.Collections;

public class Move : MonoBehaviour {
	public int moveSpeed = 10;// per second
	public bool isComputer = false;
	Vector3 computerDirection = Vector3.left;
									
	
	// Use this for initialization
	void Start () 
	{
	
	}
	
	// Update is called once per frame
	void Update () 
	{
		
		if(!isComputer) PlayerMove();
		else ComputerMove();
	
		
	}
	
	void ComputerMove()
	{
		Vector3 newPosition = Vector3.zero;// >run > attach to process
		newPosition = computerDirection *(moveSpeed * Time.deltaTime);
		
		newPosition = newPosition + transform.position;
		if(newPosition.x > 107)
		{
			newPosition.x = 107;
			computerDirection.x *= -1;
		
		}
		else if (newPosition.x < -108)
		{
			newPosition.x = -108;
			computerDirection.x *= -1;
		}
		
		transform.position = newPosition;
	}
	
	void PlayerMove()
	{
		Vector3 moveDirection = Vector3.zero;
		Vector3 newPosition = Vector3.zero;
		
		
		//if(Input.GetKey(KeyCode.UpArrow))moveDirection.y += 1;
		//if(Input.GetKey(KeyCode.DownArrow))moveDirection.y -= 1;
		if(Input.GetKey(KeyCode.LeftArrow))moveDirection.x -=1;
		if(Input.GetKey(KeyCode.RightArrow))moveDirection.x += 1;
		
		moveDirection = moveDirection * (moveSpeed * Time.deltaTime);
		
		
		newPosition = transform.position + moveDirection;
		
		//newPosition.y = Mathf.Clamp(newPosition.y,-79, 85);
		newPosition.x = Mathf.Clamp(newPosition.x, -107, 108);
		transform.position = newPosition;
		
	}

}



